// 页面form 与 接口data 数据结构互相转换
// 检验检测
import dictUtil2 from '@/common/js/dictUtil2.js';
import {separator, imageDomain} from '@/common/js/resource.js';
import tool from '@/common/js/tools.js';
export default {
	/**
	 * 将接口返回的res.data转换成页面的formData
	 * @param {Object} data 接口返回的data
	 * @return {Object} 页面formData
	 */
	newForm(data) {
		return {
			id: data.ID || data.FangZhiID,
			companyId: data.QiYeID,
			siteId: data.XiaoShaChangSuoID, // 消杀场所
			site_name: dictUtil2.getDictLabel1('site', data.XiaoShaChangSuoID), // 消杀场所
			equipmentId: data.XiaoShaSheBeiID, // 消杀设备
			equipment: dictUtil2.getDictLabel1('equipment', data.XiaoShaSheBeiID), // 消杀设备
			begDate: data.KaiShiTime, // 开始时间
			expDate: data.JieShuTime, // 结束时间
			images1: tool.addImageDomain(data.LiuDangZhaoPianUrl), // 留档照片
			_add_time_str: data.FangZhiDate, // 创建时间
		}
	},
	/**
	 * 将接口返回的res.data转换成页面的dataList
	 * @param {Array} list 接口返回的list
	 * @return {Object} 页面dataList
	 */
	newFormList(list) {
		let arr = list.map(data => {
			return {
				id: data.ID || data.FangZhiID,
				companyId: data.QiYeID,
				siteId: data.XiaoShaChangSuoID, // 消杀场所
				site_name: dictUtil2.getDictLabel1('site', data.XiaoShaChangSuoID), // 消杀场所
				equipmentId: data.XiaoShaSheBeiID, // 消杀设备
				equipment: dictUtil2.getDictLabel1('equipment', data.XiaoShaSheBeiID), // 消杀设备
				begDate: data.KaiShiTime, // 开始时间
				expDate: data.JieShuTime, // 结束时间
				images1: tool.addImageDomain(data.LiuDangZhaoPianUrl), // 留档照片
				_add_time_str: data.FangZhiDate, // 创建时间
			}
		})
		return arr;
	},
	/**
	 * 将页面页面的formData转换成接口需要的data
	 * @param {Object} form 页面formData
	 * @return {Object} 传给接口的data
	 */
	newApiData(data) {
		return {
			FangZhiID: data.id || '',
			QiYeID: data.companyId,
			FangZhiDate: data._add_time_str,
			KaiShiTime: data.begDate,
			JieShuTime: data.expDate,
			XiaoShaChangSuoID: data.siteId,
			XiaoShaSheBeiID: data.equipmentId,
			LiuDangZhaoPianUrl: data.images1.replaceAll(imageDomain, ''),
		}
	},
	// 比较新form和原form是否相同（无变化）
	compare(form1, form2){
		return form1.id             == form2.id           
		    && form1.siteId         == form2.siteId
			&& form1.equipmentId    == form2.equipmentId
			&& form1.begDate        == form2.begDate
			&& form1.expDate        == form2.expDate
			&& form1.images1        == form2.images1
	},
}